package org.apache.lucene.store;

/**
 * 
 *
 */
// TODO: make resizable
public class ByteArrayIndexOutput extends IndexOutput {
  private byte[] bytes;
  private int position = 0;
  
  public ByteArrayIndexOutput() {
    
  }
  
  public ByteArrayIndexOutput(int length) {
    bytes = new byte[length];
  }
  
  public byte[] toByteArray() {
    return bytes;
  }
  
  public void flush() {}
  
  public long getFilePointer() {
    return position;
  }
  
  public void writeBytes(byte[] b, int offset, int length) {
    System.arraycopy(b, offset, bytes, position, length);
  }
  
  public void writeBytes(byte[] b, int length) {
    System.arraycopy(b, 0, bytes, position, length);
  }
  
  public void writeByte(byte b) {
    bytes[position] = b;
    position++;
  }
  
  public void seek(long pointer) {
    throw new UnsupportedOperationException("");
  }
  
  public void close() {}
  
  public long length() {
    return bytes.length;
  }
}
